Don't run @ember/owner polyfill on ember-source itself#324
Merged
NullVoxPopuli merged 1 commit intoember-cli:nvp/its-vite-timefrom Apr 19, 2026
Conversation
With ember-cli#323 landed, `ember-lts-4.12` flips to: Uncaught ReferenceError: Cannot access 'getOwner' before initialization at app-*.js line N ember-source >= 4.12's `@ember/application/index.js` re-exports the real implementations from `@ember/owner` as aliases: import { getOwner as actualGetOwner, setOwner as actualSetOwner } from '@ember/owner'; export const getOwner = actualGetOwner; export const setOwner = actualSetOwner; `babel-plugin-ember-polyfill-get-and-set-owner-from-ember-owner` rewrote the source of that import to `@ember/application` — turning the module into a self-import that rollup then collapses into `const getOwner = getOwner` (TDZ). The plugin already tries to skip ember-source paths, but the guard only short-circuits when the file is outside `.embroider/`; in a vite compat build ember-source lives at `node_modules/.embroider/rewritten-packages/ember-source.*/` so it fell through and got rewritten. Gate the plugin through babel `overrides` with a `test` filter that excludes any path containing `/ember-source/`. The polyfill still runs where it needs to (e.g. `@glimmer/[email protected]`'s `import { setOwner } from '@ember/owner'`, which is how min-supported started passing in ember-cli#323). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the regression on
ember-lts-4.12introduced by #323:Root cause
ember-source
>= 4.12's@ember/application/index.jsre-exportsgetOwner/setOwnerfrom@ember/ownerunder aliases, then reassigns them asconsts:babel-plugin-ember-polyfill-get-and-set-owner-from-ember-owner(added in #323) rewrote thefrom '@ember/owner'at the top of that file tofrom '@ember/application'— the module's own specifier — so rollup bundled it as a self-import. Theconst getOwner = actualGetOwnerline then becomes (effectively)const getOwner = getOwner, which trips TDZ at load time.The plugin already tries to skip ember-source files with this guard:
But in a vite compat build ember-source lives at
node_modules/.embroider/rewritten-packages/ember-source.*/node_modules/ember-source/..., so the path contains both/ember-source/and/.embroider/— the guard falls through and rewrites the file.min-supporteddidn't hit this on Ember 4.2 because that version's@ember/applicationdoesn't import from@ember/ownerin the first place.Fix
Move the polyfill plugin out of the main
pluginslist intobabel.overrides, with atestfilter that skips anything whose filename contains/ember-source/:...macros.babelMacros, ...(isCompatBuild ? [ [ 'babel-plugin-debug-macros', { flags: [{ source: '@glimmer/env', flags: { DEBUG: true } }], }, ], - 'babel-plugin-ember-polyfill-get-and-set-owner-from-ember-owner', ] : []), ], + overrides: isCompatBuild + ? [ + { + test: (filename) => + filename !== undefined && !filename.includes('/ember-source/'), + plugins: [ + 'babel-plugin-ember-polyfill-get-and-set-owner-from-ember-owner', + ], + }, + ] + : [],This keeps the rewrite running where it's actually needed (
@glimmer/[email protected]'simport { setOwner } from '@ember/owner', which is what #323 was targeting), and leaves ember-source alone.A proper fix probably belongs upstream in the plugin (the existing filename guard likely intended to skip ember-source unconditionally), but this unblocks CI without needing a plugin release.
Test plan
ember-lts-4.12locally → 31 pass, 0 failmin-supportedlocally → 31 pass, 0 fail (polyfill still runs on@glimmer/component)ember-lts-4.12andmin-supportedjobs on CI go green🤖 Generated with Claude Code